﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using PowerCreator.LMS.Common.Utils;
//using PowerCreator.LMS.Logic.Common;
//using PowerCreator.LMS.Model.Entity;

public partial class sysadmin_CourseManager_CheckupResource : System.Web.UI.Page
{

    //PowerCreator.LMS.Logic.CourseManager.ManagerCourseResourceType objcoursetypelogic = new PowerCreator.LMS.Logic.CourseManager.ManagerCourseResourceType();
    //PowerCreator.LMS.Logic.CourseManager.ManagerResourceInfo objResourceInfologic = new PowerCreator.LMS.Logic.CourseManager.ManagerResourceInfo();
    //PowerCreator.LMS.Logic.CourseManager.ManagerCourseInfo courseManager = new PowerCreator.LMS.Logic.CourseManager.ManagerCourseInfo();
    //PowerCreator.LMS.Logic.VirtualManager.ManagerVirtual virtualManager = new PowerCreator.LMS.Logic.VirtualManager.ManagerVirtual();
    //PowerCreator.LMS.Logic.Log.FileInfoLog log = new PowerCreator.LMS.Logic.Log.FileInfoLog();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {            
            string courseid = "0";
            string resourceid = "0";
            if (Request.QueryString["CourseID"] != null)
            {
                courseid = Request.QueryString["CourseID"].ToString();
                courseid = Base64.Decode(courseid);
                ViewState["CourseID"] = courseid;
            }
            if (Request.QueryString["ResourceID"] != null)
            {
                resourceid = Request.QueryString["ResourceID"].ToString();
                resourceid = Base64.Decode(resourceid);
                ViewState["ResourceID"] = resourceid;
            }
            BinderCourse();

            BinderCourseType();
            BinderPG();
        }
    }
    /// <summary>
    /// 绑定课程信息
    /// </summary>
    private void BinderCourse()
    {
        //string search = string.Format("");
        //DataTable dt = courseManager.Query(search);
        //ddlCourse.DataSource = dt;
        //ddlCourse.DataTextField = "CourseName";
        //ddlCourse.DataValueField = "Course_Id";
        //ddlCourse.DataBind();
        //ListItem li = new ListItem();
        //li.Text = "未选择课程";
        //li.Value = "0";
        //ddlCourse.Items.Insert(0,li);
    }
    private void BinderPG()
    {
        //int courseid = int.Parse(ViewState["CourseID"].ToString());
        //CourseInfo info = new CourseInfo();
        //info = courseManager.Load(courseid);
        
        //int resourceid = int.Parse(ViewState["ResourceID"].ToString());
        //ResourceInfo rinfo = new ResourceInfo();
        //rinfo = objResourceInfologic.load(resourceid);

        //txt_AuthorName.Value = rinfo.AuthorName;
        //FreeTextBox1.Text = rinfo.Description;

        //txt_DutyName.Value = rinfo.DutyName;
        //txt_EntryFileName.Value = rinfo.EntryFileName;
        ////txt_FolderName.Value = rinfo.FolderName;
        //txt_ResourceName.Value = rinfo.ResourceName;
        //txt_Url.Value = rinfo.Url;
        //txt_VideoTime.Value = rinfo.VideoTime.ToString();
        ////if (rinfo.IsSCROM == 1)
        ////{
        ////    CheckBox_IsSCROM.Checked = true;
        ////}
        ////else
        ////{
        ////    CheckBox_IsSCROM.Checked = false;
        ////}
        //dpdlst_TypeName.SelectedValue = rinfo.ResourceTypeID.ToString();
        //dpdlst_TypeName.Enabled = false;
    }
    private void BinderCourseType()
    {
        //DataTable dt = new DataTable();
        //dt = objcoursetypelogic.Query("");
        //dpdlst_TypeName.DataSource = dt;
        //dpdlst_TypeName.DataTextField = "TypeName";
        //dpdlst_TypeName.DataValueField = "TypeID";
        //dpdlst_TypeName.DataBind();
    }
    protected void submitFind232_ServerClick(object sender, EventArgs e)
    {
        //if (!CheckPageData()) return;
        //PowerCreator.LMS.Model.Entity.ResourceInfo objinfo = new ResourceInfo();
        //objinfo = objResourceInfologic.load(int.Parse(ViewState["ResourceID"].ToString()));
        //objinfo.ResourceName = txt_ResourceName.Value;
        //objinfo.CourseID = int.Parse(ddlCourse.SelectedValue.ToString());
        //objinfo.ResourceTypeID = int.Parse(dpdlst_TypeName.SelectedValue);
        //objinfo.VideoTime = int.Parse(txt_VideoTime.Value);
        //objinfo.AuthorName = txt_AuthorName.Value;
        //objinfo.DutyName = txt_DutyName.Value;
        ////if (CheckBox_IsSCROM.Checked)
        ////{
        ////    objinfo.IsSCROM = 1;
        ////}
        ////else
        ////{
        ////    objinfo.IsSCROM = 0;
        ////}
        //objinfo.Description = FreeTextBox1.Text;
        //objinfo.Url = txt_Url.Value;
        ////objinfo.FolderName = txt_FolderName.Value;
        //objinfo.EntryFileName = txt_EntryFileName.Value;
        //objinfo.State = 0;
        //objinfo.ResourceTime = 0;
        //objinfo.OpenMode = 0;
        //string msg = objResourceInfologic.Update(objinfo);
        //string CourseID = objinfo.CourseID.ToString();
        ////Script.Alert(Page, "", msg);
        //Script.ShowAndRedirect(this, msg, "CheckUpResourceList.aspx?courseID=" + CourseID);
    }
    private bool CheckPageData()
    {
        //if (string.IsNullOrEmpty(txt_ResourceName.Value))
        //{
        //    Script.Alert(Page, "resname", "资源名称不能为空!");
        //    return false;
        //}
        //if (string.IsNullOrEmpty(txt_VideoTime.Value))
        //{
        //    Script.Alert(Page, "resname", "资源时长不能为空!");
        //    return false;
        //}
        //if (!PageValidate.IsNumber(txt_VideoTime.Value))
        //{
        //    Script.Alert(Page, "msg", "资源时长应为数字类型!");
        //    return false;
        //}
        //if (int.Parse(txt_VideoTime.Value) < 0)
        //{
        //    Script.Alert(Page, "msg", "资源时长不能为 0 !");
        //    return false;
        //}
        //if (ddlCourse.SelectedValue.ToString() == "0")
        //{
        //    Script.Alert(Page,"mksg","请选择一个课程!");
        //    return false;
        //}
        return true;
    }
    protected void btnTestFile_Click(object sender, EventArgs e)
    {
       //PowerCreator.LMS.Logic.Log.FileInfoLog log = new PowerCreator.LMS.Logic.Log.FileInfoLog();

       // string openurl = txt_Url.Value + txt_EntryFileName.Value;
       // WriteLog(openurl);
       // //log.WiteFile("openurl=" + openurl);
       // // openurl = openurl.Replace("\\","/");
       // if (string.IsNullOrEmpty(openurl))
       // {
       //     Script.Alert(Page, "msg", "测试文件URL不能为空!");
       //     return;
       // }

       // if (objResourceInfologic.ExistsResourcePath(openurl))
       // {
       //     Script.Alert(Page, "msg", "恭喜！可以正确打开该文件!");
       //     return;
       // }
       // else
       // {
       //     Script.Alert(Page, "msg", "打开文件失败了，请重新更改文件路径!");
       //     if (txt_Url.Disabled)
       //         txt_Url.Disabled = true;

       //     if (txt_EntryFileName.Disabled)
       //         txt_EntryFileName.Disabled = true;
       //     return;
       // }        
    }
    private void WriteLog(string msg)
    {
        //log.WriteFile(msg, "TestFile");
    }
    protected void btnReset_Click(object sender, EventArgs e)
    {
        //string url = "CheckUpResourceList.aspx?courseID=" + Base64.Encode("0");
        //Script.RedirectURL(url);
    }
    protected void btnPreview_Click(object sender, EventArgs e)
    {
        //string url = txt_Url.Value + txt_EntryFileName.Value;
        //Script.NewOpenURL(Utils.WebRoot + url);
    }
}
